#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        bool letter[128] = { false };
        int left = 0, right = 0, max1 = 0, n = s.size();
        if (n <= 1) return n;
        while (right < n)
        {
            if (letter[s[right]] == false)
            {
                letter[s[right]] = true;
                max1 = max(right - left + 1, max1);
                ++right;
            }
            else
            {
                while (left < right && letter[s[right]]) letter[s[left++]] = false;
            }
        }
        return max1;
    }
};